# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import wx                        # This module uses the new wx namespace
import images

_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

#---------------------------------------------------------------------------

class My_PasswordDialog(wx.Dialog):
    def __init__(self, parent, title, pos=wx.DefaultPosition,
                 size=wx.DefaultSize):
        
#        global field
        
        wx.Dialog.__init__(self, parent, -1, title, pos, size)
        
        #-------------------------------------------------------------------
        
        self.parent = parent
        
        #-------------------------------------------------------------------

        # Simplified init method
        self.createWidget()
        self.doLayout()

        #-------------------------------------------------------------------
        
        self.Centre(wx.BOTH)
        
        #-------------------------------------------------------------------
     
        self.ReturnValue = self.ShowModal()
        self.Destroy()
        
    #----------------------------------------------------------------------- 

    def createWidget(self):         
        # dialogicon = images.Icon_Delete.GetIcon()
        # dialogicon = wx.Icon("Icons/icon_Delete.ico", wx.BITMAP_TYPE_ICO)
        # self.SetIcon(dialogicon)
        
        #-------------------------------------------------------------------

        bmp = images.Logo_Delete.GetBitmap()
        self.logo = wx.StaticBitmap(self, -1)
        self.logo.SetBitmap(bmp)
        
        #-------------------------------------------------------------------
        
        self.txt = wx.StaticText(self, -1,
                                 label=_("Please enter the password :"),
                                 style=wx.ALIGN_LEFT)
        
        #-------------------------------------------------------------------
        
        self.line = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
        
        #-------------------------------------------------------------------
        
        self.field = wx.TextCtrl(self, -1, value="", size=(250, -1),
                                 style=wx.TE_LEFT | wx.TE_PASSWORD  |
                                 wx.BORDER_THEME)

        if wx.Platform == "__WXMSW__":
            self.field.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.NORMAL)) 

        elif wx.Platform == "__WXMAC__":
            self.field.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
            
        self.field.SetForegroundColour("#00aa00")
        self.field.SetInsertionPoint(0)
        self.field.SetFocus()

        #-------------------------------------------------------------------
        
        self.btnOK = wx.Button(self, id=wx.ID_OK, label="")
        self.btnCancel = wx.Button(self, id=wx.ID_CANCEL, label="")

        # Bind a button event to an events handler
        self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK)
        self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel)

        self.btnOK.SetDefault()
        
    #----------------------------------------------------------------------- 

    def doLayout(self):           
        imgSizer = wx.BoxSizer(wx.VERTICAL)
        txtSizer = wx.BoxSizer(wx.VERTICAL)
        imgTxtSizer = wx.BoxSizer(wx.HORIZONTAL)
        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        
        #----------
        
        imgSizer.Add(self.logo, 0, wx.ALL, 5)
        txtSizer.Add(self.txt, 0, wx.ALL, 5)
        txtSizer.Add(self.field, 1, wx.ALL | wx.EXPAND, 5)
        imgTxtSizer.Add(imgSizer, 0, wx.ALIGN_CENTER, 0)
        imgTxtSizer.Add(txtSizer, 1, wx.ALL, 0)
        lineSizer.Add(self.line, 1, wx.ALL, 0)
        btnSizer.Add(self.btnOK, 0, wx.ALL, 10)
        btnSizer.Add(self.btnCancel, 0, wx.TOP | wx.BOTTOM | wx.RIGHT, 10)
        mainSizer.Add(imgTxtSizer, 1, wx.ALL | wx.EXPAND, 5)
        mainSizer.Add(lineSizer, 0, wx.ALIGN_CENTRE | wx.EXPAND, 0)
        mainSizer.Add(btnSizer, 0, wx.ALIGN_RIGHT)
        
        #----------
        
        self.SetAutoLayout(True)
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        
    #-----------------------------------------------------------------------
     
    def getpassword(self):
        return self.field.GetValue()

     
    def PressedButton(self):
        return self.ReturnValue

        
    def OnOK(self, event):
        self.EndModal(1)

     
    def OnCancel(self, event):
        self.EndModal(2)


